from time import sleep
from selenium.webdriver.common.by import By
from base.base_page import BasePage

class CaseDemoPage(BasePage):
    iframe_element = (By.XPATH, '/html/body/iframe') #没有ID、name，通过标签定位
    if_element_text = (By.XPATH, '/html/body/table/tbody/tr/td[1]/a[1]') #点击链接测试，获取文本Link Test
    dianji_wo= (By.XPATH, '/html/body/input[2]') #点击"Click me"
    select_element1 = (By.ID, 's1Id') #选择框
    select_element2 = (By.ID,'s2Id') #选择框
    select_element3 = (By.ID,'s3Id') #选择框
    alert_element = (By.NAME, 'b1') #警告框



    def jinru_iframe_element(self):#进入iframe
        self.iframe_switch(self.iframe_element) #切换到iframe
        text=self.get_text(self.if_element_text)#获取文本
        self.click(self.if_element_text)#点击链接
        return text

    def tuichu_iframe_element(self): #退出iframe
        self.iframe_switch(self.iframe_element)  # 切换到iframe
        text = self.get_text(self.if_element_text)  # 获取文本
        print(text)
        self.iframe_switche_exit()  # 退出iframe
        return self.get_attribute(self.dianji_wo, 'value')  # 获取iframe外属性值

    def select_demo(self): #选择框测试
        self.get_select(self.select_element1, 'index',2) #通过索引三种方式选则index=2
        self.get_select(self.select_element2, 'value','o3') #通过value
        self.get_select(self.select_element3, 'text','o1') #通过文本选择
        sleep(5) #等待2秒



    def alret_accept(self):
        self.click(self.alert_element,page_name='alert确认',)
        self.get_alert('accept')#接受警告框
        sleep(3)
    def alret_dismiss(self):
        self.click(self.alert_element, page_name='alert取消', )
        self.get_alert('dismiss')#忽略警告框
        sleep(3)
    def alret_text(self):
        self.click(self.alert_element, page_name='alert获取文本', )
        ll=self.get_alert('text')#获取警告框文本
        sleep(3)
        return ll

    def ActionChai_CS(self):
        self.get_ActionChain(self.alert_element, 'click')
        sleep(3)
        self.get_alert('dismiss')

        self.get_ActionChain(self.alert_element, 'double_click')
        sleep(3)
        self.get_alert('dismiss')
        sleep(3)
        self.get_ActionChain(self.alert_element, 'move')
        self.get_ActionChain(self.alert_element, 'click')
        sleep(3)






